<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增课程目录')" />
    <th:block th:include="include :: jasny-bootstrap-css" />
    <style>
        .edui-button.edui-for-135editor .edui-button-wrap .edui-button-body .edui-icon{
            background-image: url("http://static.135editor.com/img/icons/editor-135-icon.png") !important;
            background-size: 85%;
            background-position: center;
            background-repeat: no-repeat;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-lessoncatalog-add">
            <input name="lessonId" class="form-control" type="hidden"  th:value="${lessonId}">
            <input name="type" class="form-control" type="hidden"  th:value="${type}">
            <div class="form-group" th:style="'display:' + @{(${type == 1} ? 'block' : 'none')} + ''">
                <label class="col-sm-3 control-label">图片：</label>
                <div class="col-sm-8">
                    <input id="imgUri" name="imgUri" type="hidden">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <div class="fileinput-new thumbnail" style="width: 230px; height: 500px;">
                            <img src="">
                        </div>
                        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 230px; max-height: 500px;"></div>
                        <div>
                            <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" class="image"></span>
                            <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group" th:style="'display:' + @{(${type == 2} ? 'block' : 'none')} + ''">
                <label class="col-sm-3 control-label">富文本：</label>
                <div class="col-sm-8">
                    <script id="container" name="content" style="width:360px;height:420px;"  type="text/plain"></script>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sort" class="form-control" type="text" th:value="${sort}" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <th:block th:include="include :: ueditor-js" />
    <script type="text/javascript">
        var prefix = ctx + "lesson/lessoncatalog"
        $("#form-lessoncatalog-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-lessoncatalog-add').serialize());
            }
        }


        $('.image').on('change.bs.fileinput', function (e) {
        	var file = $(this)[0].files[0];
        	var data = new FormData();
	        data.append("file", file);
	        $.ajax({
	            type: "POST",
	            url: ctx + "common/uploadOSS",
	            data: data,
	            cache: false,
	            contentType: false,
	            processData: false,
	            dataType: 'json',
	            success: function(result) {
	            	$('#imgUri').val(result.url);
	            	$.modal.alertSuccess("图片上传成功");
	            },
	            error: function(error) {
	                alert("图片上传失败。");
	            }
	        });

        });

        var ue = UE.getEditor('container',{
            initialFrameHeight:600,
            focus:true,
            toolbars:[
            ['bold','italic', 'underline', 'fontborder', 'strikethrough',  '135editor','rowspacingtop', 'rowspacingbottom', 'lineheight','removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|','superscript', 'subscript', 'link' ]],
            focusInEnd:true
        });

        function submitHandler() {
            if ($.validate.form()) {
                let data = $('#form-lessoncatalog-add').serializeArray();
                var media = ue.getContent();
                data.push({"name": "media", "value": media});
                $.operate.save(prefix + "/add", data);
            }
        }

    </script>
</body>
</html>